package com.hnucm.springboot.controller;

import com.hnucm.springboot.pojo.Person;
import com.hnucm.springboot.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PersonController {
    @Autowired
    PersonService personService;
    @RequestMapping("personlist")
    public String personlist(Model model){
        model.addAttribute("personlist",personService.findAllPerson());
        return "personlist.html";
    }
    @RequestMapping("deletepersonbyid")
    public String deletepersonbyid(int id,int idcardid){
       personService.deletePersonById(id,idcardid);
        return "redirect:/personlist";
    }
    @RequestMapping("addPerson")
    public String addPerson(){
        return "addPerson.html";
    }
    @RequestMapping("addPersoncommit")
    public String addPersoncommit(Person person){
        personService.addPerson(person);
        return "redirect:/personlist";
    }
    @RequestMapping("updateperson")
    public String addPersoncommit(Model model,Person person){
        model.addAttribute("id",person.getId());
        model.addAttribute("name",person.getName());
        model.addAttribute("age",person.getAge());
        return "updateperson.html";
    }

    @RequestMapping("updatePersoncommit")
    public String updatePersoncommit(Person person){
    personService.updatePerson(person);
        return "redirect:/personlist";
    }
}
